package dao.impl;

import bean.Users;
import dao.UsersDao;
import utils.DruidUtils;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class UsersDaoimpl extends DruidUtils implements UsersDao {
    @Override
    public Users isUserExist(String username, String password) {

        Users user = null;
        try {
            String sql = "select * from users where loginname = ?and password = ?" ;
            List list = new ArrayList();
            list.add(username);
            list.add(password);
            rs = query(sql, list);
            user = null;
            if (rs == null){
                return null;
            }
            while (rs.next()){
                user = new Users();
                user.setLoginName(rs.getString("loginname"));
                user.setUseid(rs.getInt("useid"));
                user.setRealname(rs.getString("realname"));
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            closeall();
        }
        return user;
    }
}
